home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / util / libs / regex.lha / regex / rexx / gr.rexx next >
Encoding:
OS/2 REXX Batch file  |  1999-04-23  |  898 b   |  37 lines

  1. /* mini rexx grep - slow verbose version */
  2.  
  3. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  4. l="regex.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  5.  
  6. if ~open("STDERR","CONSOLE:","W") then stderr="STDOUT"
  7.  
  8. prg=programname("NOEXT")
  9. if ~RMH_ReadArgs("RE/A,FILE/A/M,ICASE/S") then do
  10.     call writeln(stderr,fault(ioerr(),prg))
  11.     exit
  12. end
  13.  
  14. re=parm.0.value
  15. if parm.2.flag then flags = flags "ICASE"
  16. else flags = ""
  17. do m=0 to parm.1.mult-1
  18.     do f=0 to expand("A",parm.1.value.m,"FILE")-1
  19.         file=a.f
  20.         if ~open(in,file,"R") then call writeln(stderr,prg": file '"file"' not found")
  21.         else do
  22.             do i=0 while ~eof(in)
  23.                 l = readln(in)
  24.                 match=rematch(re,l,flags,"P")
  25.                 if match>1 then do
  26.                     call writeln(stderr,"prg:" regerr)
  27.                     exit
  28.                 end
  29.                 else
  30.                     if match=0 then
  31.                         say "file:'"file"' line:"i "spos:"p.so "epos:"p.eo
  32.             end
  33.             call close(in)
  34.         end
  35.     end
  36. end
  37.